//
//  WJHeaderView.m
//  天气
//
//  Created by dllo on 16/8/23.
//  Copyright © 2016年 WJ. All rights reserved.
//

#import "WJHeaderView.h"
#import "NSString+WJDateString.h"
#import "WJTitleLable.h"
#define kWJWidth  [UIScreen mainScreen].bounds.size.width
#define kWJHeight [UIScreen mainScreen].bounds.size.height

@interface WJHeaderView ()

/** weather-->temperature 温度 */
@property (nonatomic, strong) WJLabel *temperatureLable;

/** weather-->info 多云 */
@property (nonatomic, strong) WJImageView *infoImageView;
@property (nonatomic, strong) WJTitleLable *infoLable;

/** weather-->img 风级 */
@property (nonatomic, strong) WJTitleLable *imgLabel;



/** pm25 空气质量  */
@property (nonatomic, strong) WJTitleLable *pm25Lable;

/** weather-->humidity  湿度 */
@property (nonatomic, strong) WJTitleLable *humidityLable;

/** pressure 气压 */
@property (nonatomic, strong) WJTitleLable *pressureLable;


@end

@implementation WJHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
    }
    return self;
}

- (void)createView
{
    // 日期
    UILabel *dadeLable = [[UILabel alloc]initWithFrame:CGRectMake(20, 20,  kWJWidth / 2, 30)];
    NSString *week = [NSString getWeekDayFordate:[[NSDate date]timeIntervalSince1970]];
    NSString *date = [NSString getCurrentDay];
    dadeLable.text = [NSString stringWithFormat:@"%@  %@",date,week];
    dadeLable.textColor = [UIColor whiteColor];
    [self addSubview:dadeLable];
    
    // Button
    self.placeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.placeButton.frame = CGRectMake(kWJWidth - 180, 20, 160, 20);
    self.placeButton.titleLabel.textColor = [UIColor whiteColor];
    self.placeButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.placeButton];
    
    // 温度 25°
    self.temperatureLable = [[WJLabel alloc]initWithFrame:CGRectMake(0, 100, kWJWidth, 100)];
    self.temperatureLable.textAlignment = 1;
    self.temperatureLable.font = [UIFont systemFontOfSize:100];
    [self addSubview:self.temperatureLable];
    
    //多云的图片
    self.infoImageView = [[WJImageView alloc]initWithFrame:CGRectMake(kWJWidth / 2 - 100, 220, 20, 20)];
    [self addSubview:self.infoImageView];
    
    // 多云Label
    self.infoLable = [[WJTitleLable alloc]initWithFrame:CGRectMake(kWJWidth / 2 - 75, 220, 30, 20)];
    [self addSubview:self.infoLable];
    
    // 风向:东北风 1级
    self.imgLabel = [[WJTitleLable alloc]initWithFrame:CGRectMake(kWJWidth / 2 - 30, 220, kWJWidth / 2-50, 20)];
    [self addSubview:self.imgLabel];
    
    // 空气质量:
    self.pm25Lable = [[WJTitleLable alloc]initWithFrame:CGRectMake(10, 300, kWJWidth / 3 - 10, 20)];
    [self addSubview:self.pm25Lable];

    // 相对湿度
    self.humidityLable = [[WJTitleLable alloc]initWithFrame:CGRectMake(kWJWidth / 3, 300, kWJWidth / 3, 20)];
    [self addSubview:self.humidityLable];

    // 气压
    self.pressureLable = [[WJTitleLable alloc]initWithFrame:CGRectMake(kWJWidth / 3 * 2 , 300, kWJWidth / 3 - 10, 20)];
    [self addSubview:self.pressureLable];

    
}

- (void)setRealtime:(NSDictionary *)realtime
{
    _realtime = realtime;
    
    self.temperatureLable.text = [NSString stringWithFormat:@"%@°",realtime[@"weather"][@"temperature"]];
    
    self.infoImageView.image = [WJImageView imageWithDayName:realtime[@"weather"][@"info"]];
    
    self.infoLable.text = realtime[@"weather"][@"info"];
    
    self.imgLabel.text = [NSString stringWithFormat:@"风向: %@ %@",realtime[@"wind"][@"direct"],realtime[@"wind"][@"power"]];
    
    self.humidityLable.text = [NSString stringWithFormat:@"相对湿度: %@ %@",realtime[@"weather"][@"humidity"],@"%"];
    
    self.pressureLable.text = [NSString stringWithFormat:@"气压: %@Pa",realtime[@"pressure"]];
}


- (void)setPm25:(NSDictionary *)pm25
{
    _pm25 = pm25;
    
    self.pm25Lable.text = [NSString stringWithFormat:@"空气质量: %@",pm25[@"quality"]];
    
}























@end
